package com.qiwenshare.file.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qiwenshare.common.result.RestResult;
import com.qiwenshare.file.api.RoleFilePermissionService;
import com.qiwenshare.file.component.InitData;
import com.qiwenshare.file.domain.RoleFilePermission;
import com.qiwenshare.file.dto.role.BatchModifyRoleFilePermissionDto;
import com.qiwenshare.file.util.SpringBeanUtil;
import com.qiwenshare.file.vo.department.DepartmentTreeVo;
import com.qiwenshare.file.vo.role.RoleFilePermissionVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 角色文件操作权限(RoleFilePermission)表控制层
 *
 * @author MJ
 * @since 2023-10-11 15:51:35
 */
@RestController
@RequestMapping("roleFilePermission")
public class RoleFilePermissionController{
    /**
     * 服务对象
     */
    @Resource
    private RoleFilePermissionService roleFilePermissionService;

    /**
     * 得到所有的部门
     *
     * @return
     */
    @Operation(summary = "得到所有的角色文件权限列表", description = "得到所有的角色文件权限列表", tags = {"角色文件权限管理"})
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public RestResult<List<RoleFilePermissionVo>> list(@RequestParam(value = "userFileId") String userFileId) {
        List<RoleFilePermissionVo> list = (SpringBeanUtil.copy(roleFilePermissionService.queryList(userFileId), RoleFilePermissionVo.class)).stream().peek(p-> {
            p.setRoleName(InitData.getRoleNameById(p.getRoleId()));
            p.setCreateUser(InitData.getStaffNameByUserId(p.getCreateUserId()));
        }).collect(Collectors.toList());

        return RestResult.success().data(list);
    }

    /**
     * 得到所有的部门
     *
     * @return
     */
    @Operation(summary = "批量编辑", description = "批量编辑", tags = {"角色文件权限管理"})
    @RequestMapping(value = "/modifyBatch", method = RequestMethod.POST)
    @ResponseBody
    public RestResult<Boolean> modifyBatch(@RequestBody BatchModifyRoleFilePermissionDto filePermissionDto) {
        return RestResult.success().data(roleFilePermissionService.modifyBatch(filePermissionDto));
    }

    /**
     * 得到所有的部门
     *
     * @return
     */
    @Operation(summary = "得到所有的角色文件权限列表", description = "得到所有的角色文件权限列表", tags = {"角色文件权限管理"})
    @RequestMapping(value = "/listByUser", method = RequestMethod.GET)
    @ResponseBody
    public RestResult<List<RoleFilePermissionVo>> listByUser() {
        return RestResult.success().data(roleFilePermissionService.queryListByUser());
    }

}

